home *** CD-ROM | disk | FTP | other *** search
/ Apple WWDC 1996 / WWDC96_1996 (CD).toast / Technology Materials / MacApp Release 10 / MacApp Release 10 - HD Ready / Libraries / Framework / Sources / UDrawingEnvironment.cp < prev    next >
Encoding:
Text File  |  1996-04-03  |  4.9 KB  |  157 lines  |  [TEXT/MPS ]

  1. //----------------------------------------------------------------------------------------
  2. // UDrawingEnvironment.cp 
  3. // Copyright © 1991-96 by Apple Computer, Inc. All rights reserved.
  4. //----------------------------------------------------------------------------------------
  5.  
  6. #ifndef __UDRAWINGENVIRONMENT__
  7. #include "UDrawingEnvironment.h"
  8. #endif
  9.  
  10. // MacApp
  11.  
  12. #ifndef __UMACAPPUTILITIES__
  13. #include "UMacAppUtilities.h"
  14. #endif
  15.  
  16. #ifndef __USTREAM__
  17. #include "UStream.h"
  18. #endif
  19.  
  20. // ANSI
  21.  
  22. #ifndef __STRING__
  23. #include <string.h>
  24. #endif
  25.  
  26.  
  27. //========================================================================================
  28. // CLASS TDrawingEnvironment
  29. //========================================================================================
  30. #undef Inherited
  31. #define Inherited TObject
  32.  
  33. #pragma segment MAOpen
  34. MA_DEFINE_CLASS_M1(TDrawingEnvironment, Inherited);
  35.  
  36. //----------------------------------------------------------------------------------------
  37. // TDrawingEnvironment constructor
  38. //----------------------------------------------------------------------------------------
  39. #pragma segment MAOpen
  40.  
  41. TDrawingEnvironment::TDrawingEnvironment() :
  42.     fPenSize(1,1),
  43.     fPenMode(patCopy),
  44.     
  45.     fPenPattern(qd.black),
  46.     fForegroundColor(gRGBBlack),
  47.     fBackgroundColor(gRGBWhite)
  48. {
  49. } // TDrawingEnvironment::TDrawingEnvironment
  50.  
  51. //----------------------------------------------------------------------------------------
  52. // TDrawingEnvironment destructor
  53. //----------------------------------------------------------------------------------------
  54. #pragma segment MADestructorRes
  55.  
  56. TDrawingEnvironment::~TDrawingEnvironment()
  57. {
  58. }
  59.  
  60. //----------------------------------------------------------------------------------------
  61. // TDrawingEnvironment::IDrawingEnvironment: 
  62. //----------------------------------------------------------------------------------------
  63. #pragma segment MAOpen
  64.  
  65. void TDrawingEnvironment::IDrawingEnvironment()    
  66. {
  67.     this->IObject();
  68. } // TDrawingEnvironment::IDrawingEnvironment 
  69.  
  70. //----------------------------------------------------------------------------------------
  71. // TDrawingEnvironment::ReadFrom: 
  72. //----------------------------------------------------------------------------------------
  73. #pragma segment MAReadResource
  74.  
  75. void TDrawingEnvironment::ReadFrom(TStream* aStream)     
  76. {
  77.     Inherited::ReadFrom(aStream);
  78.     
  79.     fPenSize = aStream->ReadPoint();
  80.     fPenMode = aStream->ReadInteger();
  81.  
  82.     aStream->ReadBytes(&fPenPattern, sizeof(Pattern));
  83.     aStream->ReadRGBColor(fForegroundColor);
  84.     aStream->ReadRGBColor(fBackgroundColor);
  85. } // TDrawingEnvironment::ReadFrom 
  86.  
  87. //----------------------------------------------------------------------------------------
  88. // TDrawingEnvironment::WriteTo: 
  89. //----------------------------------------------------------------------------------------
  90. #pragma segment MAWriteResource
  91.  
  92. void TDrawingEnvironment::WriteTo(TStream* aStream)     
  93. {
  94.     Inherited::WriteTo(aStream);
  95.  
  96.     aStream->WritePoint(fPenSize);
  97.     aStream->WriteInteger(fPenMode);
  98.  
  99.     aStream->WriteBytes(&fPenPattern, sizeof(Pattern));
  100.     aStream->WriteBytes(&fForegroundColor, sizeof(CRGBColor));
  101.     aStream->WriteBytes(&fBackgroundColor, sizeof(CRGBColor));
  102. } // TDrawingEnvironment::WriteTo 
  103.  
  104. //----------------------------------------------------------------------------------------
  105. // TDrawingEnvironment::GetGrafPort: 
  106. //----------------------------------------------------------------------------------------
  107. #pragma segment MAViewRes
  108.  
  109. GrafPtr TDrawingEnvironment::GetGrafPort()
  110. {
  111.     return NULL;
  112. } // TDrawingEnvironment::GetGrafPort 
  113.  
  114. //----------------------------------------------------------------------------------------
  115. // TDrawingEnvironment::Prepare: 
  116. //----------------------------------------------------------------------------------------
  117. #pragma segment MAViewRes
  118.  
  119. void TDrawingEnvironment::Prepare()     
  120. {
  121.     GetPenState(&fSavedPenState);
  122.     GetIfColor(fSavedForegroundColor);
  123.     GetIfBkColor(fSavedBackgroundColor);
  124. } // TDrawingEnvironment::Prepare 
  125.  
  126. //----------------------------------------------------------------------------------------
  127. // TDrawingEnvironment::Setup: 
  128. //----------------------------------------------------------------------------------------
  129. #pragma segment MAViewRes
  130.  
  131. void TDrawingEnvironment::Setup()     
  132. {
  133.     PenNormal();
  134.     PenSize(fPenSize.h,fPenSize.v);
  135.     PenMode(fPenMode);
  136.     PenPat(&fPenPattern);
  137.     SetIfColor(fForegroundColor);
  138.     SetIfBkColor(fBackgroundColor);
  139. } // TDrawingEnvironment::Setup 
  140.  
  141. //----------------------------------------------------------------------------------------
  142. // TDrawingEnvironment::Complete: 
  143. //----------------------------------------------------------------------------------------
  144. #pragma segment MAViewRes
  145.  
  146. void TDrawingEnvironment::Complete()     
  147. {
  148.     SetPenState(&fSavedPenState);
  149.     SetIfColor(fSavedForegroundColor);
  150.     SetIfBkColor(fSavedBackgroundColor);    
  151. } // TDrawingEnvironment::Complete 
  152.  
  153. //----------------------------------------------------------------------------------------
  154. // End of UDrawingEnvironment.cp
  155.  
  156. #pragma segment Inline
  157.